import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { getMenus } from '../api/home'

/**
 * 参数1：仓库的名字
 * 参数2：组合式Api的写法
 * 参数3：持久化配置
 */
export const useHomeStore = defineStore(
  'home',
  () => {
    // state
    const menuList = ref([])

    // getters
    const getMenuList = computed(() => menuList.value)

    // actions
    const setMenuList = async () => {
      const res = await getMenus()

      console.log('---res---', res)
      menuList.value = res.data
    }

    return {
      getMenuList,
      setMenuList
    }
  },
  {
    persist: true
  }
)
